package com.hxd.otc.module.convenience.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.module.convenience.bean.PrepaidGoodsBean;
import com.hxd.otc.utils.ResourceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/12/13 0013.
 * description ${话费充值Adapter}
 */
public class PrepaidRechargeAdapter extends BaseAdapter<PrepaidRechargeAdapter.PrepaidRechargeHolder, PrepaidGoodsBean> {

    private boolean mEnable;

    public PrepaidRechargeAdapter(Context context) {
        super(context);
    }

    @SuppressLint("DefaultLocale")
    @Override
    protected void onBindHolder(@NonNull PrepaidRechargeHolder holder, int position) {
        PrepaidGoodsBean item = getItem(position);
        holder.tvFaceValue.setText(ResourceUtil.getString(R.string.sub_rmb_chinese, item.getSellPrice()));
        holder.tvPaymentPrice.setText(ResourceUtil.getString(R.string.sell_price_sub_sub, item.getVolume(), item.getSymbol()));
        holder.itemView.setEnabled(mEnable);
        holder.tvFaceValue.setEnabled(mEnable);
        holder.tvPaymentPrice.setEnabled(mEnable);
    }

    @NonNull
    @Override
    public PrepaidRechargeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PrepaidRechargeHolder(mInflater.inflate(R.layout.item_prepaid_recharge, parent, false));
    }

    public void setEnable(boolean enable) {
        if (mEnable != enable) {
            mEnable = enable;
            notifyDataSetChanged();
        }
    }

    static class PrepaidRechargeHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_face_value)
        TextView tvFaceValue;
        @BindView(R.id.tv_payment_price)
        TextView tvPaymentPrice;
        PrepaidRechargeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
